-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add flag to append hash to pages to ensure unique titles #509
Conversation
) | ||
path := strings.Join(append(meta.Parents, meta.Space, meta.Title), "/") | ||
pathHash := sha256.Sum256([]byte(path)) | ||
meta.Title = fmt.Sprintf("%s - %x", meta.Title, pathHash[0:4]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meta.Title = fmt.Sprintf("%s - %x", meta.Title, pathHash[0:4]) | |
meta.Title = fmt.Sprintf("%s - %x", meta.Title, pathHash[:7]) |
let's take 7 characters here, just to be safe (in case someone generates a lot of pages)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pathHash
here is an array of bytes being printed as hexadecimal, so each byte is printed as two characters. The first four bytes and the first eight hexadecimal characters are the same, so I could change it to [:7]
of the hex string if you think that is more clear.
Either way, I'll add a comment there since it isn't clear what's happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I didn't see that it's a byte array and hex representation. This looks good (and a comment is a good idea). Ignore my suggestion then :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment for clarity, and included other suggestions.
Thanks for the review!
dde43e3
to
9ab0c67
Compare
Thanks for the contribution! |
This adds a command line flag and environment variable to configure mark to append hash values to page titles.
This helps solve the issue where multiple pages with the same name, but under different parents, will conflict (#450).
Another solution could be to allow arbitrary prefix/postfix text, and/or make this computed hash value available as a template variable to be inserted at any point.